import React, { Component } from 'react'
import './index.scss'

class TopBar extends Component{
	constructor(props) {
		super(props);
		this.state = {

		}
	}

	render() {
		return (
			<div id="topBar">
					<div className="container">
					{
							this.props.left ?
									<div className="left" onClick={this.handleLeft.bind(this,this.props.leftTo)}>
											<span className={this.props.leftIcon}/>
									</div>
							:null
					}
					<div className="title">
							{this.props.title}
					</div>
					{
							this.props.left ?
									<div className="right" onClick={this.handleRight.bind(this,this.props.rightTo)}>
											<span className={this.props.rightIcon}/>
									</div>
							:null
					}
					</div>
			</div>
		)
	}

	handleRight(to) {
			switch (to) {
					case "search":
							this.props.history.push('/search');
							return;
					default:
							this.props.history.push('/')
			}
	}
	handleLeft(to) {
			switch (to) {
					case "return":
							console.log(this.props.history.goBack());
							return;
					case "service":
							console.log('kefu');
							return;
					default:
							this.props.history.push('/')
			}
	}

}

export default TopBar
